package cn.b.sky.common.utils;

import java.text.NumberFormat;

public class MathUtils {
  
  private MathUtils() {
    // Hide the constructor
  }

  public static String getPercent(int x, int y) {

    return MathUtils.getPercent(x, y, 2);
  }

  public static String getPercent(int x, int y, int count) {
    int leave = (x * 100) % y;
    if (leave == 0) { //除的尽
      return (x * 100) / y + "%";
    } else {
     return MathUtils.getPercent((float) x, (float) y, count);
    }
  }
  
  public static String getPercent(float x, float y, int count) { 
      float tempresult =  x / y;
      NumberFormat numberFormat = NumberFormat.getPercentInstance();// 获取格式化类实例
      numberFormat.setMinimumFractionDigits(count);// 设置小数位
      return numberFormat.format(tempresult);
  }

 /*public static void main(String[] args)
  {
   System.out.println(3f*100/8f);
  }*/
}
